package com.springbootmybatis.controller;

import com.alibaba.fastjson.JSONObject;
import com.springbootmybatis.entity.DailyPlan;
import com.springbootmybatis.service.DailyPlanService;
import com.springbootmybatis.utils.JSONResultHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

/**
 * 日程相关控制类
 * @author 谢呀
 */
@RestController
@RequestMapping("/daily-plan")
public class DailyPlanController {

    private static Logger logger = LoggerFactory.getLogger(DailyPlanController.class);

    @Autowired
    DailyPlanService dailyPlanServiceImpl;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String add(@RequestBody DailyPlan dailyPlan){
        logger.info("/add, dailyPlan={}", dailyPlan);
        JSONObject jsonObject = new JSONObject();
        try {
            if (dailyPlan == null){
                return JSONResultHandler.handler(jsonObject, "-1001", "参数不能为空");
            }
            dailyPlanServiceImpl.addDailyPlan(dailyPlan);
            JSONResultHandler.handlerObject(jsonObject, "0", "新增成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonObject.toString();
    }

}
